﻿using demo1.Entity;
using demo1.Interface;
using SqlSugar;

namespace demo1.Service
{
    public class PeopleService : Ipeople
    {
        public SqlSugarClient _db;

        public PeopleService(SqlSugarClient db)
        {
            _db = db;
        }
        public int Add(PeopleEntity p)
        {
            return _db.Insertable(p).ExecuteCommand();
        }

        public int Delete(string id)
        {
            return _db.Deleteable(new PeopleEntity() { Id = id }).ExecuteCommand();
        }

        public List<PeopleEntity> Get(string? id)
        {
            //if(id == null)
            //{
            //    return _db.Queryable<PeopleEntity>().ToList();
            //}
            //else
            //{
            //    return _db.Queryable<PeopleEntity>().Where(P=>P.Id == id).ToList();
            //}
            return _db.Queryable<PeopleEntity>().WhereIF(!string.IsNullOrEmpty(id),p=>p.Id == id).ToList();
        }

        public int Update(PeopleEntity p)
        {
            return _db.Updateable(p).ExecuteCommand();
        }
    }
}
